<?php

/**
 * MVM_MALL 网上商店系统 标 签
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-01 $
 * $Id: tag.php  www.mvmmall.com$
 * ---------------------------------------------
*/

require_once './include/common.inc.php';

if ($action=='write'){
	!$m_check_id && move_page(GetBaseUrl('logging','login'));
	$mm_tag_sift = explode(',',$mm_tag_sift);
	foreach($mm_tag_sift as $value){
		strpos($tag_name,$value)!==false && show_msg('board_advertisement');
	}
	$row         = false;
	$row         = array(
	'goods_id'  => $goods_id,
	'tag_name'  => $tag_name,
	'member_id' => $m_check_uid
	);
	$row          = dhtmlchars($row);
	$db->insert("{$tablepre}tag",$row);
	move_page(dreferer());
} elseif ($action=='list'){
	require_once MVMMALL_ROOT.'./include/pager.class.php';
	$scarch_sql        = false;
	$goods_tag         = false;
	//我的标签
	if ($mytag==1 && is_numeric($m_check_uid)){
		$scarch_sql    = "WHERE member_id='$m_check_uid'";
		$lang['tag']   = $lang['my_tag'];
	}
	$total_count       = $db->counter("{$tablepre}tag",$scarch_sql);
	$page              = $page ? (int)$page:1;
	$list_num          = 20;
	$rowset            = new Pager($total_count,$list_num,$page);
	$from_record       = $rowset->_offset();
	$result            = $db->query("SELECT tag_id, member_id, tag_name, COUNT(tag_id) AS tag_count FROM `{$tablepre}tag` $scarch_sql GROUP BY tag_name LIMIT $from_record,$list_num");
	while ($rt = $db->fetch_array($result)) {
		$tag_name       = urlencode($rt['tag_name']);
		$rt['tag_name'] = "<a href='tag.php?action=view&tag_name=$tag_name' target='_blank'>$rt[tag_name] ($rt[tag_count])</a>";
		$goods_tag[]    = $rt;
	}
	if ($rewrite == 1) {
		$baseurl        = str_replace('1.html','',GetBaseUrl('tag',$action))."&mytag=$mytag";
		$exc            = '.html';
	} else{
		$baseurl        = GetBaseUrl('tag',$action)."&mytag=$mytag&page=";
	}
	$page_list          = $rowset->link($baseurl,$exc);
	$navigation         = make_navigation($lang['tag'],$baseurl.$page.$exc);//导航
	require_once MVMMALL_ROOT . 'header.php';
	include_once template('tag');
	footer();
}

//标签商品列表
elseif ($action=='view' && $tag_name){
	require_once MVMMALL_ROOT.'./include/pager.class.php';
	$search_sql  = false;
	$tag_name    = dhtmlchars($tag_name);
	$search_sql  = "where tag_name='$tag_name'";
	$total_count = $db->counter("{$tablepre}tag",$search_sql,'tag_id');

	$page        = $page ? (int)$page:1;
	$list_num    = $mm_limit_list;//后台可控制显示数量
	$rowset      = new Pager($total_count,$list_num,$page);
	$from_record = $rowset->_offset();
	$query       = "SELECT a.*,b.* FROM `{$tablepre}tag` a LEFT JOIN `{$tablepre}goods_table` b ON a.goods_id=b.uid WHERE a.tag_name='$tag_name' ORDER BY b.uid ASC limit $from_record, $list_num ";
	$result      = $db->query($query);
	while($list  = $db->fetch_array($result)) {
		$goods[] = goods_array($list);
	}
	if($rewrite==1){
		$baseurl = str_replace('1.html','',GetBaseUrl('tag',$action))."?tag_name=$tag_name&page=";
		$exc     = '.html';
	}else {
		$baseurl = GetBaseUrl('tag',$action)."&tag_name=$tag_name&page=";
	}
	$page_list   = $rowset->link($baseurl, $exc);
	$navigation  = make_navigation($lang['search_result'],$baseurl.$page);//导航
	require_once MVMMALL_ROOT.'header.php';
	require_once template('search');
	footer();
}
else {
	show_msg('pass_worng');
}
